package com.tanhua.app.controller;

import com.tanhua.app.service.SmallVideosService;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.VideoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideosController {

    @Autowired
    private SmallVideosService smallVideosService;

    /**
     * 发布视频
     */
    @PostMapping
    public ResponseEntity saveVideo(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        smallVideosService.saveVideo(videoThumbnail, videoFile);

        return ResponseEntity.ok(null);
    }


    /**
     * 小视频列表
     */
    @GetMapping
    public ResponseEntity<PageResult<VideoVo>> findPageVideos(@RequestParam(defaultValue = "1", required = false) Integer page,
                                         @RequestParam(defaultValue = "10", required = false) Integer pagesize) {

        PageResult<VideoVo> pageResult = smallVideosService.findPageVideos(page, pagesize);

        return ResponseEntity.ok(pageResult);
    }

}
